package com.mediastory.spsserver.app.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mediastory.spsserver.app.dao.AppDao;
import com.mediastory.spsserver.app.domain.App;
import com.mediastory.spsserver.app.service.AppSvc;

/**
 * @author Jaewon Choi
 *
 */

@Service
@Transactional
public class AppSvcImpl implements AppSvc {

	@Autowired
	AppDao appDao;
	
	public AppSvcImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<App> findbyList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<App>) (appDao.SelectList(condition));
	}

	public Map<String, Object> findbyListPaging(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("appList", (List<App>) (appDao.SelectList(condition)));
		resultMap.put("appListTotalCnt", (Integer) (appDao.SelectListTotalCnt(condition)));
		
		return resultMap;
	}

	@Override
	public App findby(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return appDao.select(id);
	}

	@Override
	public App add(App app) throws Exception {
		// TODO Auto-generated method stub
		App result = appDao.insert(app);
		
		return result;
	}

	@Override
	public App modify(App app) throws Exception {
		// TODO Auto-generated method stub
		return appDao.update(app);
	}

	@Override
	public int remove(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return appDao.delete(condition);
	}

	@Override
	public String findbyChkDupl(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		
		String result = "true";
		Integer cnt = (Integer) (appDao.SelectListTotalCnt(condition));
		if(cnt != null && cnt == 0){
			result = "false";
		}
		
		return result;
	}

}